<%--
 * @fileName save.jsp
 * @author  科泰集团教研团队
 * @createTime 2024/10/13 21:57
 * @lastModify 2024/10/13 21:57
 * @version 1.0.0
 --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>科泰超市管理系统</title>
    <%--  导入公共头部信息  --%>
    <%@include file="/WEB-INF/layout/head.jsp" %>
    <%--  有其他css样式可以在这里引入或编写  --%>
</head>

<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <!-- 引入左边导航菜单 -->
        <jsp:include page="/WEB-INF/layout/left-nav.jsp"></jsp:include>
        <!-- 引入左边导航菜单 -->

        <!-- 引入顶部导航 -->
        <jsp:include page="/WEB-INF/layout/top-nav.jsp"></jsp:include>
        <!-- 引入顶部导航 -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="title_left">
                        <h3>${goods.id == null ? '新增' : '修改'}商品信息</h3>
                    </div>
                </div>
                <div class="clearfix"></div>

                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_content">
                                <form action="${ctx}/main/goods/save" enctype="multipart/form-data"
                                        class="form-horizontal form-label-left"  novalidate method="post">
                                    <%--   修改时隐藏域提交用户id  --%>
                                    <input value="${goods.id}" name="id"  type="hidden" />
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="goodsName">
                                            商品名称 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <div class="col-md-6 col-sm-6 col-xs-12">
                                                <input id="goodsName" class="form-control col-md-7 col-xs-12"
                                                       value="${goods.goodsName}" name="goodsName"
                                                       required="required" type="text">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="goodsDesc">
                                            商品描述 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="goodsDesc" class="form-control col-md-7 col-xs-12"
                                                   value="${goods.goodsDesc}" name="goodsDesc"
                                                   required="required" type="text">
                                        </div>
                                    </div>

                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="isPostage">
                                            是否包邮 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select id="isPostage" class="form-control" name="isPostage" required>
                                                <option value="">---------------请选择是否包邮---------------</option>
                                                <option value="0" ${goods.isPostage == 0 ? "selected='selected'" : ""}>不包邮</option>
                                                <option value="1" ${goods.isPostage == 1 ? "selected='selected'" : ""}>包邮</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="goodsPrice">
                                            商品单价
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="goodsPrice" class="form-control col-md-7 col-xs-12"
                                                   value="${goods.goodsPrice}" name="goodsPrice" type="text">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="orderNuit">
                                            商品单位
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="orderNuit" class="form-control col-md-7 col-xs-12"
                                                   value="${goods.orderNuit}" name="orderNuit" type="text">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="orderNum">
                                            库存数量
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="orderNum" class="form-control col-md-7 col-xs-12"
                                                   value="${goods.orderNum}" name="orderNum" type="number">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="categoryId">
                                            商品类型
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select id="categoryId" name="categoryId" class="form-control">
                                                <c:forEach items="${categoryList}" var="category">
                                                    <option value="${category.id}" ${category.id == goods.categoryId ? "selected='selected'" : ""}>${category.name}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
<%--                                    <div class="item form-group">--%>
<%--                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="goodsImgPath">--%>
<%--                                            商品样图--%>
<%--                                        </label>--%>
<%--                                        <div class="col-md-6 col-sm-6 col-xs-12">--%>
<%--                                            <input id="goodsImgPath" name="goodsImgPath" class="form-control col-md-7 col-xs-12" type="file" >--%>
<%--                                        </div>--%>
<%--                                    </div>--%>

                                    <div class="ln_solid"></div>
                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-3">
                                            <button id="send" type="submit" class="btn btn-success">提交</button>
                                            <button type="button" onclick="history.back()" class="btn btn-primary">返回</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 底部内容 -->
        <jsp:include page="/WEB-INF/layout/footer.jsp"></jsp:include>
        <!-- 底部内容 -->

        <script type="text/javascript" src="${ctx}/statics/js/common/save.js"></script>
        <script>
            $(function(){
                // 如果获取到生日，则作为默认
                let defaultDate = "<fmt:formatDate value="${sysUser.birthday}" pattern="yyyy-MM-dd" />";
                // 配置日期选择组件
                $('#birthday-datetimepicker').datetimepicker({
                    format: 'YYYY-MM-DD',
                    locale: moment.locale('zh-cn'),
                    defaultDate : defaultDate
                });
                $('#birthday-datetimepicker').data("DateTimePicker")
                    .maxDate(new moment().format("YYYY-MM-DD"));
            })
        </script>

        <script>
            var inputElement = document.getElementById('account');
            if (!inputElement.readOnly) {
                $(function () {
                    $("#account").on("input", function () {
                        // 输入过程中清除显示信息
                        clearInfo("#account");
                    }).on("blur", function () {
                        // 失去焦点事件中，请求后端检查account是否存在
                        $.ajax({
                            type: "GET",//请求类型
                            url: ctx + "/main/user/accountExist",//请求的url
                            data: {account: $(this).val()},//请求参数
                            dataType: "json",//ajax接口（请求url）返回的数据类型
                            success: function (data) {//data：返回数据（json对象）
                                if (data.exist == 1) {
                                    //账号已存在，提示错误提示
                                    showErrorInfoFor("#account", "该用户账号已存在")
                                } else if (data.exist == 0) {
                                    //账号可用，提示正确提示
                                    showSuccessInfoFor("#account", "该账号可以使用")
                                } else if (data.error) {
                                    // 后台传了错误提示，显示
                                    showErrorInfoFor("#account", data.error)
                                }
                            },
                            error: function (data) {//当访问时候，404，500 等非200的错误状态码
                                showErrorInfoFor("#account", "请求异常，请联系管理员解决！")
                            }
                        });
                    })
                })
            }
        </script>

    </div>
</div>

</body>
</html>

